//
//  SLInformationAlertView.m
//  SulitLoanDemo
//
//  Created by 虞嘉伟 on 2025/2/22.
//

#import "SLInformationAlertView.h"
#import <YYKit.h>
#import <Masonry.h>


@implementation SLInformationAlertView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = UIColorHex(#000000A6);
        
        [self addSubview:self.content];
        [self.content addSubview:self.pannel];
        [self.content addSubview:self.confirmButton];
        
        [self.pannel addSubview:self.titleLabel];
        [self.pannel addSubview:self.closeButton];
        [self.pannel addSubview:self.decorate];
        [self.pannel addSubview:self.customView];
        [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self).inset(20);
            make.centerY.equalTo(self);
        }];
        [self.pannel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self.content);
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.pannel).inset(12);
            make.top.equalTo(self.pannel).inset(18);
            make.width.mas_equalTo(self.titleLabel.intrinsicContentSize.width+20*2);
            make.height.mas_equalTo(30);
        }];
        [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.pannel).inset(12);
            make.centerY.equalTo(self.titleLabel);
            make.width.height.mas_equalTo(30);
        }];
        [self.decorate mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.pannel).inset(-1);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
            make.height.mas_equalTo(10);
        }];
        [self.customView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.pannel);//.inset(14);
            make.top.equalTo(self.decorate.mas_bottom);//.offset(9);
            make.bottom.equalTo(self.pannel);//.inset(30);
            make.height.mas_equalTo(251);
        }];
        [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.content).inset(75);
            make.top.equalTo(self.pannel.mas_bottom).offset(14);
            make.height.mas_equalTo(45);
            make.bottom.equalTo(self.content);
        }];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.titleLabel.intrinsicContentSize.width+20*2);
    }];
}

#pragma mark - 点击事件
- (void)closeButtonAction:(UIButton *)button {
    [self removeFromSuperview];
}

- (void)confirmButtonAction:(UIButton *)button {
    [self removeFromSuperview];
    //!self.leftButtonCallback ?: self.leftButtonCallback(button);
}



- (UIView *)content {
    if (!_content) {
        _content = [UIView new];
    }
    return _content;
}
- (UIView *)pannel {
    if (!_pannel) {
        _pannel = [UIView new];
        _pannel.backgroundColor = UIColor.whiteColor;
        _pannel.layer.cornerRadius = 20;
    }
    return _pannel;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.text = @"Select date";
        _titleLabel.font = aspectDefaultFont(16);
        _titleLabel.backgroundColor = UIColorHex(#1B1B1B);
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = UIColor.whiteColor;
        _titleLabel.layer.masksToBounds = YES;
        _titleLabel.layer.cornerRadius = 15;
    }
    return _titleLabel;
}
- (UIButton *)closeButton {
    if (!_closeButton) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setImage:[UIImage imageNamed:@"icon_close"] forState:UIControlStateNormal];
        [_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeButton;
}
- (UIImageView *)decorate {
    if (!_decorate) {
        _decorate = [UIImageView new];
        _decorate.backgroundColor = UIColorHex(#FDC5E0);
        _decorate.layer.borderColor = UIColorHex(#1B1B1B).CGColor;
        _decorate.layer.borderWidth = 1;
    }
    return _decorate;
}
- (UIView *)customView {
    if (!_customView) {
        _customView = [UIView new];
    }
    return _customView;
}
- (UIButton *)confirmButton {
    if (!_confirmButton) {
        _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmButton setTitle:@"Confirm" forState:UIControlStateNormal];
        [_confirmButton setImage:[UIImage imageNamed:@"btn_more_white"] forState:UIControlStateNormal];
        [_confirmButton jk_setImagePosition:LXMImagePositionRight spacing:10];
        [_confirmButton setTitleColor:UIColorHex(#1B1B1B) forState:UIControlStateNormal];
        _confirmButton.backgroundColor = UIColorHex(#FDC5E0);
        _confirmButton.titleLabel.font = aspectDefaultFont(16);
        _confirmButton.layer.cornerRadius = 20;
        _confirmButton.layer.borderColor = UIColorHex(#1B1B1B).CGColor;
        _confirmButton.layer.borderWidth = 1.5;
        [_confirmButton addTarget:self action:@selector(confirmButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmButton;
}

@end

